package com.cndongtai.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.cndongtai.dao.BaseDao;
import com.cndongtai.dao.inter.FirmwareMapper;
import com.cndongtai.po.Firmware;

@Repository("firmwareDao")
public class FirmwareDao extends BaseDao implements FirmwareMapper {

	@Override
	public boolean addFirmware(Firmware firmware) {
		SqlSession sqlSession = getSqlSession();
		try {
			FirmwareMapper operation = sqlSession.getMapper(FirmwareMapper.class);
			return operation.addFirmware(firmware);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return false;
	}

	@Override
	public List<Firmware> queryFirmwareList() {
		SqlSession sqlSession = getSqlSession();
		try {
			FirmwareMapper operation = sqlSession.getMapper(FirmwareMapper.class);
			return operation.queryFirmwareList();
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

	@Override
	public boolean deleteFirmware(Firmware firmware) {
		SqlSession sqlSession = getSqlSession();
		try {
			FirmwareMapper operation = sqlSession.getMapper(FirmwareMapper.class);
			return operation.deleteFirmware(firmware);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return false;
	}

	@Override
	public Firmware queryFirmwareById(Long id) {
		SqlSession sqlSession = getSqlSession();
		try {
			FirmwareMapper operation = sqlSession.getMapper(FirmwareMapper.class);
			return operation.queryFirmwareById(id);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

}